import java.util.Stack;

public class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        if(s1.empty()){
            s1.push(x);
            return;
        }
        while(!s2.empty()){
            int num = s1.pop();
            s2.push(num);
            s1.push(x);
        }
    }

    public int pop() {
        while(!s1.empty()) {
            int num = s1.pop();
            s1.push(num);
        }
        if(s2.empty()) {
            return -1;
        }
        return s2.pop();
    }


    public int peek() {
        while(!s1.empty()) {
            int num = s1.pop();
            s2.push(num);
        }
        if(s2.empty()) {
            return -1;
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}